package service

import (
	"net/http"
	"strconv"

	"github.com/gin-gonic/gin"
)

// 用户

type user struct{}

var UserController = user{}

type Iuser struct {
	Title string `json:"title"`
	Age   int    `json:"age"`
	Id    int    `json:"id"`
}

var userList = []Iuser{
	{
		Title: "张三",
		Age:   18,
		Id:    1,
	},
	{
		Title: "李四",
		Age:   99,
		Id:    2,
	},
}

func (u user) List(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, userList)
}

func (u user) Detail(ctx *gin.Context) {
	var id = ctx.Param("id")
	for _, v := range userList {
		var val, _ = strconv.Atoi(id)
		if v.Id == val {
			ctx.JSON(http.StatusOK, v)
		}
	}

}

// 文章
func Article(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, userList)
}
